#!/usr/bin/python3
#coding:utf-8
__author__ = 'merci'

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

#发件人邮箱
sender_mail = 'shevechco@qq.com'
#这个是邮箱授权码，不是登录密码
sender_pass = '*******'
#收件人邮箱
receiver = 'yang.su@***.com'

#这个是邮件正文，有html格式文本，plain文本格式文档
message = MIMEText('这是一个python使用sendmail的测试邮件', 'plain', 'utf-8')
#昵称和发件人邮箱
message['From'] = formataddr(['merci', sender_mail])
#收件人邮箱和昵称
message['To'] = formataddr(['yang.su', receiver])
#这里算是邮件标题
message['Subject'] = 'python sendmail test !'

try:
    _send = smtplib.SMTP_SSL("smtp.qq.com", 465)
    #登录QQ邮箱
    _send.login(sender_mail, sender_pass)
    _send.sendmail(sender_mail, receiver, message.as_string())
    print('邮件发送成功！')
    _send.quit()
except:
    print('Failed , 邮件发送失败！')